<!--小额预对账页面-->
<template>
  <div class="app-container">
    <ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      defaultEventKey="entryTable"
    ></ht-search-form>
    <ht-table
      ref="dataTable"
      :showSerialNumber="false"
      :multi-select="false"
      :dictMap="dictMap"
      :reqConfig="reqConfig"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      @dataLoadComplete="dataLoadComplete"
      defaultEventKey="entryTable"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  // permission: 'user:xxx:xxx',
                  doFunc: () => {
                    handleAction('details', scope.row);
                  },
                },
                {
                  label: '查看原交易',
                  // permission: 'user:xxx:xxx',
                  visible: scope.row.checkFlag != '3',
                  doFunc: () => {
                    handleAction('viewTransaction', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>
    <!-- 查看原交易弹出框 -->
    <hvps-details ref="hvpsPreDetailsDialog" :dictMap="dictMap" @editComplete="editComplete" :id="id"></hvps-details>
    <!-- 明细弹出框 -->
    <hvps-view ref="hvpsViewDialog" :formData="formData" :dictMap="dictMap" @editComplete="editComplete"></hvps-view>
    <ori-view314 ref="bepsView314Dialog" :dictMap="dictMap" :formData="formData"></ori-view314>
    <ori-view315 ref="bepsView315Dialog" :dictMap="dictMap" :formData="formData"></ori-view315>

  </div>
</template>
<script>
import {
  bepsPreReconciliationQuery,
  queryOriTxn,
  ManualReconciliation,
  detail,
} from "@/api/cnaps/bizMng/beps_pre_reconciliation_query.js";
import { listPageMixin } from "@/libs/listPageMixin";
import { mapGetters } from "vuex";
import HvpsDetails from "./components/bepsPreDetailsTable";
import HvpsView from "./components/bepsPreDetails";
import OriView314 from "@/views/cnaps/bizMng/dayEndProcess/components/oriView314";
import OriView315 from "@/views/cnaps/bizMng/dayEndProcess/components/oriView315";
export default {
  name: "BepsPreReconciliationQuery",
  mixins: [listPageMixin],
  components: { OriView315, OriView314, HvpsDetails, HvpsView },
  data() {
    return {
      reqConfig: bepsPreReconciliationQuery,
      manualList: [],
      id: "",
      //数据字典
      searchFormDictList: [
        "TXN_SYSCODE",
        "Cnaps2Dict.PKG_TYPE_BEPS_RECON",
        "PKG_TYPE_BEPS_RECON",
        "BAL_FLAG",
        "BIZ_TYPE_HVPS_RECON",
        "PROCESSSTATUS",
        "PKG_TYPE_HVPSBEPS",
        "DRCTCODE",
        "BIZ_TYPE",
        "BIZ_TYPECODE",
        "PKG_TYPE"
      ],
      //  明细弹框数据
      // form表单字段
      formData: {},
      showSearch: true,
      // 查询参数
      queryParams: {
        sysCode: "BEPS",
        checkDate: "",
        msgTypeCode: "",
        checkFlag: "",
      },
      formOptions: [],
      opButtonList: () => {
        return [
          {
            label: "手工对账",
            type: "primary",
            icon: "",
            // permission: "user:xxx:xxx",
            clickFun: () => {
              this.handleAction("manualRecon");
            },
          },
        ];
      },
      tableBindColumns: [
        {
          label: `对账日期`,
          prop: "checkDate",
          sortable: false,
          type: "date",
        },
        {
          label: `系统编号`,
          prop: "sysCode",
          width: "180",
          dictCode: "TXN_SYSCODE",
          sortable: false,
        },
        {
          label: `报文类型`,
          prop: "msgTypeCode",
          width: "200",
          dictCode: "Cnaps2Dict.PKG_TYPE_BEPS_RECON",
          sortable: false,
        },
        {
          prop: "cnapsAmount",
          label: "Cnaps金额",
          width: "200",
          type: "price",
        },
        {
          label: `Cnaps中心状态`,
          prop: "cnapsProcStatus",
          width: "200",
          dictCode: "PROCESSSTATUS",
        },
        {
          prop: "innerAmount",
          label: "行内金额",
          type: "price",
        },
        {
          label: `行内中心状态`,
          prop: "innerProcStatus",
          width: "200",
          dictCode: "PROCESSSTATUS",
        },
        {
          label: `对平标志`,
          prop: "checkFlag",
          dictCode: "BAL_SIGN",
        },
      ],
    };
  },
  mounted() {
    this.formOptions = [
      {
        type: "dict",
        dict: "TXN_SYSCODE",
        prop: "sysCode",
        defaultAttr: {
          label: "系统编号",
          placeholder: "请选择系统编号",
          disabled: true,
        },
      },
      {
        type: "singleDate",
        prop: "checkDate",
        defaultAttr: {
          label: "对账日期",
          placeholder: "请选择对账日期",
          disCleanable: false,
        },
      },
      {
        type: "dict",
        dict: "Cnaps2Dict.PKG_TYPE_BEPS_RECON",
        prop: "msgTypeCode",
        defaultAttr: {
          label: "报文类型",
          placeholder: "请选择报文类型",
        },
      },
      {
        type: "dict",
        dict: "BAL_SIGN",
        prop: "checkFlag",
        defaultAttr: {
          label: "对平标志",
          placeholder: "请选择对平标志",
        },
      },
    ];
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  watch: {},
  methods: {
    editComplete(state) {
      if (state == true) {
        this.$refs.dataTable.doQuery();
      }
    },
    dataLoadComplete(tableData) {
      this.manualList = _.clone(tableData.result.data);
    },
    handleAction(type, row = {}) {
      switch (type) {
        case "manualRecon":
          // 手工对账
          let sendData = {
            preReconBepsTables: this.manualList,
          };
          ManualReconciliation(sendData).then((res) => {
            this.$refs.dataTable.doQuery();
            this.msgSuccess("操作成功！");
          });
          break;
        case "viewTransaction":
          // 查看原交易
          queryOriTxn({ id: row.id }).then((res) => {
            if ("ccms.314.001.01"===row.msgTypeCode|| "CMT301"===row.msgTypeCode){
              this.$refs.bepsView314Dialog.show("小额预对账应答信息-查看原交易明细");
            }else if ("ccms.315.001.01"===row.msgTypeCode|| "CMT302"===row.msgTypeCode){
              this.$refs.bepsView315Dialog.show("小额预对账应答信息-查看原交易明细");
            }
            else{
              this.id = row.id;
              this.$refs.hvpsPreDetailsDialog.show();
            }

          });
          break;
        case "details":
          // 明细
          detail(row).then((res) => {
            this.formData = _.clone(res.result);
            this.$refs.hvpsViewDialog.show();
          });
          break;
      }
    },
  },
};
</script>
